﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Granite.DataAnnotations;

namespace Rifts.Models.Characters
{
	partial class Character
	{
		public string Name
		{
			get { return Get<string>("Name"); }
			set { Set(value, "Name"); }
		}

		public string Alias
		{
			get { return Get<string>("Alias"); }
			set { Set(value, "Alias"); }
		}

		public string Race
		{
			get { return Get<string>("Human", "Race"); }
			set { Set(value, "Race"); }
		}

		public string RaceReference
		{
			get { return Get<string>("RaceReference"); }
			set { Set(value, "RaceReference"); }
		}




		/// <summary>
		/// This is the book/page number for the class
		/// </summary>
		public string ClassReference
		{
			get { return Get<string>("ClassReference"); }
			set { Set(value, "ClassReference"); }
		}

		public string Alignment
		{
			get { return Get<string>("Alignment"); }
			set { Set(value, "Alignment"); }
		}

		public string Sex
		{
			get { return Get<string>("Sex"); }
			set { Set(value, "Sex"); }
		}

		public int? Age
		{
			get { return Get<int?>("Age"); }
			set { Set(value, "Age"); }
		}

		public int? HeightInches
		{
			get { return Get<int?>("Height"); }
			set { Set(value, "Height"); }
		}

		[CalculatedField("HeightInches")]
		public string Height
		{
			get
			{
				if (!HeightInches.HasValue)
					return "";

				int inches;
				var feet = Math.DivRem(HeightInches.Value, 12, out inches);

				if (feet > 0 && inches > 0)
					return string.Format(@"{0}' {1}""", feet, inches);
				if (feet > 0)
					return string.Format(@"{0}'", feet);
				if (inches > 0)
					return string.Format(@"{0}""", inches);

				return "";
			}
		}

		public decimal? WeightPounds
		{
			get { return Get<decimal?>("Weight"); }
			set { Set(value, "Weight"); }
		}

		[CalculatedField("WeightPounds")]
		public string Weight
		{
			get
			{

				if (!WeightPounds.HasValue)
					return "";


				if (WeightPounds > 2000)
					return Math.Round(WeightPounds.Value, 2) + " tons";

				int ozs;
				var pounds = Math.DivRem((int)(WeightPounds * 16), 16, out ozs);

				if (pounds > 0 && ozs > 0)
					return string.Format(@"{0} lbs {1}ozs", pounds, ozs);
				if (pounds > 0)
					return string.Format(@"{0} lbs", pounds);
				if (ozs > 0)
					return string.Format(@"{0} oz", ozs);

				return "";
			}
		}

		public string Homeland
		{
			get { return Get<string>("Homeland"); }
			set { Set(value, "Homeland"); }
		}

		public string Traits
		{
			get { return Get<string>("Traits"); }
			set { Set(value, "Traits"); }
		}

		public string Insanities
		{
			get { return Get<string>("Insanities"); }
			set { Set(value, "Insanities"); }
		}

		[CalculatedField("TrustBase,TrustFromMA")]
		public int? Trust
		{
			get { return TrustBase.AddNull(TrustFromMA); }
		}

		public int? TrustBase
		{
			get { return Get<int?>("TrustBase"); }
			set { Set(value, "TrustBase"); }
		}

		[CalculatedField("IntimidateBase,IntimidateFromMA")]
		public int? Intimidate
		{
			get { return IntimidateBase.AddNull(IntimidateFromMA); }
		}

		public int? IntimidateBase
		{
			get { return Get<int?>("IntimidateBase"); }
			set { Set(value, "IntimidateBase"); }
		}

		[CalculatedField("CharmBase,CharmFromPB")]
		public int? Charm
		{
			get { return CharmBase.AddNull(CharmFromPB); }
		}

		public int? CharmBase
		{
			get { return Get<int?>("CharmBase"); }
			set { Set(value, "CharmBase"); }
		}

		[CalculatedField("ImpressBase,ImpressFromPB")]
		public int? Impress
		{
			get { return ImpressBase.AddNull(ImpressFromPB); }
		}

		public int? ImpressBase
		{
			get { return Get<int?>("ImpressBase"); }
			set { Set(value, "ImpressBase"); }
		}

		public int? Awe
		{
			get { return Get<int?>("Awe"); }
			set { Set(value, "Awe"); }
		}

		public int? HF
		{
			get { return Get<int?>("HF"); }
			set { Set(value, "HF"); }
		}

	}

	public class EditableObservableCollection<T> : Granite.Modeling.EditableObjectModelCollection<T>
	{

	}

}
